package leetcode.sort;

/**
 * @author mazouri
 * @create 2021-10-06 23:25
 */
public class _414_thirdMax {
    public int thirdMax(int[] nums) {

        long first = Long.MIN_VALUE;
        long second = Long.MIN_VALUE;
        long third = Long.MIN_VALUE;

        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == first|| nums[i] == second || nums[i] == third) continue;
            if (nums[i] > first) {
                third = second;
                second = first;
                first = (long) nums[i];
            } else if (nums[i] > second ) {
                third = second;
                second =(long) nums[i];
            } else if (nums[i] > third ) {
                third = (long)nums[i];
            }

            System.out.println("first: " + first + " second: " + second + " third: " + third);
        }

        if (third == Long.MIN_VALUE) return (int) first;

        return (int) third;
    }


    public static void main(String[] args) {
        System.out.println(new _414_thirdMax().thirdMax(new int[]{1,2,3}));
    }
}
